package com.tedu.egnotice1.controller;

import com.tedu.egnotice1.base.response.Result;
import com.tedu.egnotice1.mapper.NoticeMapper;
import com.tedu.egnotice1.pojo.dto.param.NoticeAddParam;
import com.tedu.egnotice1.pojo.dto.query.NoticeAddQuery;
import com.tedu.egnotice1.pojo.entity.Notice;
import com.tedu.egnotice1.pojo.vo.NoticeListVO;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/notice/")
public class NoticeController {
    @Autowired
    private NoticeMapper noticeMapper;
    @PostMapping("add")
    public Result add(@RequestBody NoticeAddParam noticeAddParam){
        Notice notice=new Notice();
        log.debug("添加公告："+noticeAddParam);
        BeanUtils.copyProperties(noticeAddParam,notice);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        notice.setUserId(100L);
        noticeMapper.inster(notice);
        return Result.ok();
    }
    @GetMapping("list")
    public Result list(NoticeAddQuery noticeAddQuery){
        String title=noticeAddQuery.getTitle();
        Integer type=noticeAddQuery.getType();
        List<NoticeListVO> noticeListVOS=noticeMapper.list(title,type);
        return Result.ok(noticeListVOS);
    }
}
